'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.setQuery = undefined;

var _urlEncode = require('./urlEncode');

var _urlEncode2 = _interopRequireDefault(_urlEncode);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var regUrlSearch = /^([^?]+)($|(\?.*)$)/;

var setQuery = exports.setQuery = function setQuery(url) {
    var query = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

    var urlMatch = url.match(regUrlSearch);
    if (!urlMatch) {
        return url;
    }
    var baseUrl = urlMatch[1];
    var search = urlMatch[3];

    return baseUrl + '?' + (0, _urlEncode2.default)(query, search);
};

exports.default = setQuery;